 import {httprequests} from '../../miniprogram/utils/httpReq'
 import {backimageReq} from '../../miniprogram/utils/API/imageManage'
 import{getFirstCategoryList} from '../../miniprogram/utils/API/category'
 import{getElasticList,getSpuInfo} from '../../miniprogram/utils/API/spuAndsku.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
      swiperList:[{
        id:'',
        url:[],
        type:'',
        note:[], 
    }],
    catelist:[
        {id:'',
        name:'',
        imgUrl:'',
        prentCid:'',
        catLevel:'',
        }
    ],
    prodList:[
        {id:'',
        imgUrl:'',
        price:'',
        desp:''
    }],
    cateRouterName:[],
    skuInfo:[
        {
            brandId: 35,
            brandImg: "",
            brandName: "华为",
            categoryName: "5G手机",
            catelogId: 138,
            createTime: "2024-05-05 15:10:06",
            price: 6399,
            saleCount: 0,
            skuDefaultImg: "",
            skuDesc: null,
            skuId: 90,
            skuName: "",
            skuSubTitle: " ",
            skuTitle: "",
            spuId: 24,
            status: 0,
            storeCount: 200,
            updateTime: "2024-05-07 08:26:10"
        }
    ],
    loading:true,
    pageData:{
        // keyWord: null,
        // catelogId: 138,
        // sort: "skuPrice_desc",
        // hasStock: 1,
        // // skuPrice: null,
        // brandIds:'',
        // attrs:'',
        // pageNum: 1
        currentPage:1,
        pageSize:6
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
        this.getSwiper(),
        this.getCateList(),
        this.getskuLish(),   
        this.getBackImg()
  },
  //轮播图请求
 async getSwiper(){
    var that = this;
    const res = await httprequests('swiper-manages/getswiperList','POST')
    if(res.data.code== 200){
        var iswiperList = res.data.data
      this.setData({
          swiperList:iswiperList, 
      })
    }
},
  //一级分类请求
 async getCateList(){
    var that = this;
   const res =await getFirstCategoryList()
    if(res.data.code === 200){
        var catelist = res.data.data
        var cateRouterName = []
          catelist = res.data.data.filter((item,index)=>{
              if (index <= 9) {
                  item.name = item.name.split('/')[0]
                  return item
              }
          })
        this.setData({
            catelist,
            cateRouterName
        })
    }
  },
//搜索界面
  navSearch(){
      wx.navigateTo({
        url: '/pages/search/search',
        animationType:'none'
      })
  },
//商品列表
async getskuLish(){
    var data = this.data.pageData
  const res = await getSpuInfo(data)
    if(res.data.code == 200){
        var skuInfo = res.data.data
            this.setData({
                skuInfo,
                loading : false
            })
    }
},

async getBackImg(){
   let res = await backimageReq()
},
    
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getSwiper(),
    this.getCateList(),
    this.getskuLish(),
    wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.setData({    
            currentPage: currentPage +=1,
            pageSize: 6  
    })
    console.log("触底了");
    this. getskuLish()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})